package com.guet.configuration;

import com.guet.interceptor.JwtTokenAdminInterceptor;
import com.guet.interceptor.JwtTokenUserInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
    @Autowired
    private JwtTokenUserInterceptor jwtTokenUserInterceptor;
    @Autowired
    private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;

    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");
        registry.addInterceptor(jwtTokenUserInterceptor)
                // 这里写需要拦截的请求地址
                .addPathPatterns("/student/**")
                // 这里写排除拦截的请求地址，登录地址当然不需要拦截
                .excludePathPatterns("/student/login")
                .excludePathPatterns("/student/register");

        registry.addInterceptor(jwtTokenAdminInterceptor)
                // 这里写需要拦截的请求地址
                .addPathPatterns("/teacher/**")
                // 这里写排除拦截的请求地址，登录地址当然不需要拦截
                .excludePathPatterns("/teacher/login")
                .excludePathPatterns("/teacher/register");
    }
}
